package com.woniuxy.hrp.web.AdminController;

import com.woniuxy.hrp.entity.Medicine;
import com.woniuxy.hrp.service.MedicineService;
import com.woniuxy.hrp.unityhandler.ResponseEntity;
import com.woniuxy.hrp.utils.Mednumber;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/admin/medicine")
public class MedicineController {
    @Autowired
    private MedicineService medicineService;

    //查询所有药物信息
    @GetMapping("/list")
    public ResponseEntity list(){
        List<Medicine> medicines = medicineService.findAll();
        return new ResponseEntity("200","OK",medicines);
    }

    //根据id查询药物
    @GetMapping("/update")
    public ResponseEntity findById(int id){
        Medicine medicine = medicineService.findById(id);
        return new ResponseEntity("200","OK",medicine);
    }

//    //增加药物
//    @PostMapping("/add")
//    public ResponseEntity add(@RequestBody Medicine medicine){
//        medicine.setNumber(Mednumber.getnumber());
//        medicineService.add(medicine);
//        return  ResponseEntity.SUCCESS;
//    }

    //删除药物
    @PostMapping("/del")
    public ResponseEntity del(int id){
        medicineService.del(id);
        return ResponseEntity.SUCCESS;
    }

    //修改药物
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody Medicine medicine){
        medicineService.update(medicine);
        return ResponseEntity.SUCCESS;
    }
}
